<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/5/18 0018
 * Time: 下午 6:15
 */

namespace app\index\controller;

use Gatewayclient\Gateway;
use think\Session;

class Workerman extends Common
{
    public function bind()
    {
        // 设置GatewayWorker服务的Register服务ip和端口，请根据实际情况改成实际值
        Gateway::$registerAddress = '127.0.0.1:1236';
        $client_id = input('client_id');
        // 用户已经登录，用户uid在session中
        $uid  = Session::get('userid');
        // client_id与uid绑定
        Gateway::bindUid($client_id, $uid);
        // 给client_id绑定分组1：前台推送通知消息 2：后台推送订单信息
        Gateway::joinGroup($client_id, 1);
    }

    //页面不知怎么获取发送的信息
    public function send()
    {
        Gateway::$registerAddress = '127.0.0.1:1236';
        $new_message = array('type'=>'say', 'from_client_id'=>'管理员', 'message'=>'test', 'time'=>date('Y-m-d H:i:s'));
        // 向所有人发送
        Gateway::sendToAll(json_encode($new_message));
    }
}